/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import controler.EdgeItemControler;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;
import javax.swing.JLabel;

/**
 *
 * @author borysfan
 */
public class EdgeItem extends JLabel {
    private NodeItem begin =null;
    private NodeItem end = null;
    private EdgeItemControler edgeItemControler;
    private Color toolboxcolor=Color.black;
    public EdgeItem(EdgeItemControler eic){
        setSize(50,100);
        setText("Krawędź");
        edgeItemControler = eic;
        setToolTipText("Kliknijm, aby dodać krawędź.");
    }

    public NodeItem getBegin(){
        return begin;
    }

    public NodeItem getEnd(){
        return end;
    }

    public void setToolboxColor(Color toolboxcolor){
        this.toolboxcolor=toolboxcolor;
    }

   

    public Color getToolboxColor(){
        return toolboxcolor;
    }

    @Override
    public void paint(Graphics g){
        super.paint(g);
        Stroke stroke = new BasicStroke(3);
        
        Graphics2D g2 = (Graphics2D)g;
        g2.setStroke(stroke);
        g2.setColor(getColor());
        if(begin == null || end == null){
            g2.setColor(toolboxcolor);
            g2.drawLine(0, 0, 44, 44);
        }else{
            g2.drawLine(0, 0, 44, 44);
            System.out.println(begin.getX()+" "+ begin.getY()+ " "+ end.getX()+ " "+ end.getY());
          //  g2.drawLine(begin.getX(), begin.getY(), end.getX(), end.getY());
        }
        System.out.println("EdgeItem. Maluje");
    }

    public void setBeginNode(NodeItem view) {
        System.out.println("EdgeItem. Ustawiam poczatek krawedzi");
        begin = view;
        revalidate();
        updateUI();
    }

    public void setEndNode(NodeItem view){
        this.setColor(Color.black);
        end = view;
        System.out.println("EdgeItem. Ustawiam koniec krawedzi");
        revalidate();
        updateUI();
        
    }


    public Color getColor(){
        return edgeItemControler.getModel().getColor();
    }

    public void setColor(Color color){
        System.out.println("Ustawiam kolor");
        edgeItemControler.getModel().setColor(color);
        repaint();
    }

    public Color getDefColor(){
        return edgeItemControler.getModel().getDefColor();
    }

    public void setDefColor(Color color){
        edgeItemControler.getModel().setDefColor(color);
        repaint();
    }


}
